package com.kinyx.framework.db.daos;

import static org.junit.Assert.assertNull;

import org.junit.Assert;
import org.junit.Test;

import com.kinyx.framework.db.sentence.res.Condition;
import com.kinyx.framework.db.sentence.res.KSELECT;
import com.kinyx.framework.db.sentence.res.KSQLBuilder;
import com.kinyx.framework.db.sentence.str.SELECT;
import com.kinyx.framework.db.sentence.str.SQL;
import com.kinyx.framework.db.sentence.str.SQLBuilder;
import com.kinyx.test.entities.impl.DemoEntity;
import com.kinyx.test.entities.impl.DemoEntityR;

@SuppressWarnings("deprecation")
public abstract class JDBCDao_Tester_queryOne extends SUPER {

	@Test
	public void testSuccess1() {
		this.logger.debug("queryOne using str.SQL");
		final DemoEntity entity = this.dao.queryOne(null, new SQL().x("SELECT * FROM T_DEMO WHERE ID = ?", null), DemoEntity.class);
		assertNull(entity);
	}

	@Test
	public void testSuccess2() {
		this.logger.debug("getOne using str.SELECT");
		final SELECT sentence = SQLBuilder.select().x("SELECT * FROM T_DEMO WHERE ID = ?", null);
		final DemoEntity entity = this.dao.getOne(null, sentence, DemoEntity.class);
		assertNull(entity);
	}

	@Test
	public void testSuccess3() {
		this.logger.debug("getOne using res.SELECT");
		final KSELECT sentence = KSQLBuilder.select(true)//
				.select(DemoEntityR.class)//
				.from(DemoEntityR.class)//
				.where(Condition.eq(DemoEntityR.id, null));
		final DemoEntity entity = this.dao.getOne(null, sentence, DemoEntity.class);
		assertNull(entity);
	}

	@Test
	public void testError11() {
		this.logger.debug("testError11 空指针（尚未连接数据库）");
		final SQL sql = null;
		Assert.assertThrows(NullPointerException.class, () -> { this.dao.queryOne(null, sql, DemoEntity.class); });
	}

}
